﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using TomNet.AspNetCore.Mvc;
using TomNet.AspNetCore.Mvc.Filters;
using TomNet.Data;
using TomNet.Demo.Entity.Entities;
using TomNet.Demo.Service.User;
using TomNet.Demo.Service.User.Input;
using TomNet.Entity;

namespace TomNet.Demo.Web.Controllers
{
    public class ServiceController : ApiControllerBase
    {
        private readonly IUserService _userService;

        public ServiceController(IUserService userService)
        {
            _userService = userService;
        }

        [HttpPost]
        public async Task<IActionResult> AddAsync(UserAddInput dto)
        {
            var result = await _userService.AddAsync(dto);
            return Ok(result);
        }

        [HttpPost("insert")]
        public async Task<IActionResult> InsertAsync(UserAddInput dto)
        {
            var result = await _userService.InsertAsync(dto);
            return Ok(result);
        }

        [HttpPost("create")]
        public IActionResult CreateUser(UserAddInput dto)
        {
            var result = _userService.CreateUser(dto);
            return Ok(result);
        }

        [HttpGet("users")]
        public async Task<IActionResult> UsersAsync()
        {
            var result = await _userService.QueryUserAsync(1, 3);
            return Ok(result);
        }

        [HttpGet("resetpassword/id/{id}/pwd/{pwd}")]
        public IActionResult ResetPassword(long id, string pwd)
        {
            var result = _userService.ResetPassword(id, pwd);
            return Ok(result);
        }

        [HttpGet("resetpwd/id/{id}/pwd/{pwd}")]
        public async Task<IActionResult> ResetPwdAsync(long id, string pwd)
        {
            var result = await _userService.ResetPwdAsync(id, pwd);
            return Ok(result);
        }
    }
}
